package cn.bitkit.tools.data;

import java.math.BigDecimal;
import java.text.DecimalFormat;

public class BigDecimalUtil {

    public static boolean gt(BigDecimal val1, BigDecimal val2){
        if(val1 == null || val2 == null){
            return false;
        }
        return val1.compareTo(val2) > 0;
    }

    public static boolean gte(BigDecimal val1, BigDecimal val2){
        if(val1 == null || val2 == null){
            return false;
        }
        return val1.compareTo(val2) >= 0;
    }

    public static boolean lt(BigDecimal val1, BigDecimal val2){
        if(val1 == null || val2 == null){
            return false;
        }
        return val1.compareTo(val2) < 0;
    }

    public static boolean lte(BigDecimal val1, BigDecimal val2){
        if(val1 == null || val2 == null){
            return false;
        }
        return val1.compareTo(val2) <= 0;
    }

    public static String getPercentageView(BigDecimal rate){
        rate = rate.multiply(new BigDecimal(100));
        DecimalFormat format = new DecimalFormat("####.####");
        return format.format(rate) + "%";
    }

    public static String getView(BigDecimal value){
        DecimalFormat format = new DecimalFormat("####.####");
        return format.format(value);
    }

}
